% ML TAU 2013 final project script
% Alt 2:
% Calculate norm of abs(S1 - S2) and perform linear regression based on it

%base_path = '/home/itay/TAU/IML/final';

% Add path to the libsvm
%addpath(base_path);

%
% Initialization
%
close all; clear; clc; tic;
if ~exist('dataforproject.mat','file')
    error('Data file not found in current directory')
end;
% Saving memory. Loading vars on a need to load basis only throughout
load('dataforproject.mat','X1train','X2train','gidtrain','ytrain');
fprintf('Training Data successfully loaded\n');

for k=1:3
	
	% Training set
	X1 = X1train(:,(gidtrain~=k));
	X2 = X2train(:,(gidtrain~=k));
	y = ytrain(gidtrain~=k);
	
	% Simply sum the deltas between the vectors 
	X = sum(abs(X1-X2))';

	% Create the model
	model = LinearModel.fit(X,y,'linear');

	% Testing set
	X1 = X1train(:,(gidtrain==k));
	X2 = X2train(:,(gidtrain==k));
	y = ytrain(gidtrain==k);
	
	X = sum(abs(X1-X2))';

	% Predict
	predictedY = predict(model, X);
 
	results = sum(y.*predictedY > 0) / size(y,1); 

	fprintf('Results: %f\n', results);
end


